Skip to content

Conversation

@Kakadus
Copy link

@Kakadus Kakadus commented Jan 27, 2026

Related Issue or Design Document

Close #588

On nodejs, the headers returned by fetch are immutable, following the whatwg standard. In the nextjs middleware, this leads to an TypeError when proxying e.g. POST login requests to kratos.

This clones the headers object before modification, preventing the error.

Checklist

  • I have read the contributing guidelines and signed the CLA.
  • I have referenced an issue containing the design document if my change introduces a new feature.
  • I have read the security policy.
  • I confirm that this pull request does not address a security vulnerability.
    If this pull request addresses a security vulnerability,
    I confirm that I got approval (please contact security@ory.sh) from the maintainers to push the changes.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added the necessary documentation within the code base (if appropriate).

Further comments

@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

⚠️ No Changeset found

Latest commit: 832a8a1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jan 27, 2026

@Kakadus is attempting to deploy a commit to the ory Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.02%. Comparing base (f3fad4d) to head (832a8a1).
⚠️ Report is 281 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #589       +/-   ##
===========================================
+ Coverage   42.43%   56.02%   +13.59%     
===========================================
  Files         136      174       +38     
  Lines        2008     3259     +1251     
  Branches      288      481      +193     
===========================================
+ Hits          852     1826      +974     
- Misses       1149     1358      +209     
- Partials        7       75       +68     
Components Coverage Δ
@ory/elements-react 54.92% <ø> (+18.13%) ⬆️
@ory/nextjs 62.60% <ø> (-3.38%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Kakadus
Copy link
Author

Kakadus commented Jan 27, 2026

The formatting CI error is only on unrelated files. The codecov report also looks sketchy to me, as all lines are clearly executed / are in tests.

@Kakadus Kakadus changed the title fix(nextjs): handle immutable headers returned by native fetch in middleware fix handle immutable headers returned by native fetch in middleware Jan 27, 2026
@Kakadus Kakadus changed the title fix handle immutable headers returned by native fetch in middleware fix: handle immutable headers returned by native fetch in middleware Jan 27, 2026
Copy link
Member

@jonas-jonas jonas-jonas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Looks reasonable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: immutable in nextjs middleware when deleting headers from upstream response

2 participants